import { View } from "../../../../mvc/core/View";
import { PageTool } from "../../../../common/global/PageTool";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { PetIlluEventName } from "./PetIlluEventName";
import { PetManualConfig } from "../../../resource/PetManualConfig";
import { GComboBox } from "../../../../../com/mui/controls/GComboBox";
import { MailFriendItemCellRender } from "../../mail/MailFriendItemCellRender";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Language } from "../../../../../extend/language/Language";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { TilePanel } from "../../equipment/TilePanel";
import { PetIlluSkillRenderer } from "./PetIlluSkillRenderer";
import { PageSelecter } from "../../common/pageSelect/PageSelecter";
import { PetManualInfo } from "./PetManualInfo";
import { DataEvent } from "../../../events/DataEvent";
type int = number;
//class PetIlluSkillListPanel
    
    export  class PetIlluSkillListPanel extends View
    {
        constructor()
        {
            super();
            this._allSkillArray = [];
            this._pageTool = new PageTool([], 3);
            this.init();
            Dispatcher.addEventListener(PetIlluEventName.SearchSkillByType, this.onSearchSkillByTypeHandler);
            return;
        }

        /* internal  */init(): void
        {
            this._allSkillArray = PetManualConfig.instance.getManualList(1);
            this._autoSkillCombo = new GComboBox();
            this._autoSkillCombo.styleName = "GComboboxStyle";
            this._autoSkillCombo.drawNow();
            this._autoSkillCombo.dropdown.setStyle("cellRenderer", MailFriendItemCellRender);
            this._autoSkillCombo.dropdown.setStyle("skin", ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB));
            this._autoSkillCombo.dropdown.rowCount = 10;
            this._autoSkillCombo.dropdown.rowHeight = 25;
            this._autoSkillCombo.dropdown.drawNow();
            this._autoSkillCombo.textField.setStyle("textFormat", GlobalStyle.textFormat1);
            this._autoSkillCombo.prompt = Language.getString(54086);
            this._autoSkillCombo.setSize(100, 25);
            this._autoSkillCombo.move(15, 5);
            this._autoSkillCombo.dataProvider = new DataProvider(PetManualConfig.instance.getManualList(1, 0));
            this._autoSkillCombo.addEventListener(flash.events.Event.CHANGE, this.onComboChangeHandler);
            this.addChild(this._autoSkillCombo);
            this._listPanel = new TilePanel();
            this._listPanel.setStyle("cellRenderer", PetIlluSkillRenderer);
            this._listPanel.columnWidth = 490;
            this._listPanel.rowHeight = 150;
            this._listPanel.setSize(500, 460);
            this._listPanel.move(2, 40);
            this.addChild(this._listPanel);
            this._pageTool.array = this._allSkillArray;
            this._pageBar = new PageSelecter();
            this._pageBar.mode = PageSelecter.CompleteMode;
            this._pageBar.move(200, 490);
            this._pageBar.maxPage = this._pageTool.pagesCount;
            this._pageBar.addEventListener(flash.events.Event.CHANGE, this.onChangeHandler);
            this.addChild(this._pageBar);
            this.onChangeHandler(null);
            return;
        }

        /* internal  */onChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=this._pageBar.currentPage;
            this._listPanel.dataProvider = new DataProvider(this._pageTool.getByPageNo(loc1));
            return;
        }

        /* internal  */onComboChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=(arg1.target as GComboBox).selectedItem as PetManualInfo;
            var loc2=this.getManualPageIndex(loc1);
            this._pageBar.currentPage = loc2;
            this.onChangeHandler(null);
            return;
        }

        /* internal  */onSearchSkillByTypeHandler(arg1: DataEvent): void
        {
            this._autoSkillCombo.selectedIndex = -1;
            var loc1=arg1.data as int;
            if (loc1 != -1) 
            {
                this._skillArray = PetManualConfig.instance.getManualList(1, loc1);
            }
            else 
            {
                this._skillArray = PetManualConfig.instance.getManualList(1);
            }
            this._pageTool.array = this._skillArray;
            this._pageBar.maxPage = this._pageTool.pagesCount;
            this._pageBar.currentPage = 1;
            this.onChangeHandler(null);
            return;
        }

        /* internal  */getManualPageIndex(arg1: PetManualInfo): int
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            var loc4=0;
            while (loc4 < this._skillArray.length) 
            {
                if ((loc3 = this._skillArray[loc4]).id == arg1.id) 
                {
                    loc2 = loc4 + 1;
                    break;
                }
                ++loc4;
            }
            loc1 = loc2 % 3 != 0 ? int(loc2) / 3 + 1 : loc2 / 3;
            return loc1;
        }

        /* internal */ /* var */_autoSkillCombo: GComboBox;

        /* internal */ /* var */_listPanel: TilePanel;

        /* internal */ /* var */_pageBar: PageSelecter;

        /* internal */ /* var */_listDp: DataProvider;

        /* internal */ /* var */_allSkillArray: Array<any>;

        /* internal */ /* var */_skillArray: Array<any>;

        /* internal */ /* var */_pageTool: PageTool;
    }
